package com.pospi.xstore.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pospi.xstore.R;
import com.pospi.xstore.dto.CashierCashDto;
import com.pospi.xstore.util.DoubleSave;

import java.util.List;

/**
 * Created by Qiyan on 2016/6/20.
 */
public class CashierStaticAdapter extends BaseAdapter {
    private Context context;
    private List<CashierCashDto> dtos;

    public CashierStaticAdapter(Context context, List<CashierCashDto> dtos) {
        this.context = context;
        this.dtos = dtos;
    }

    @Override
    public int getCount() {
        return dtos.size();
    }

    @Override
    public Object getItem(int position) {
        return dtos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.cashier_static_item, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.cashier_static_name);
            holder.num = (TextView) convertView.findViewById(R.id.cashier_static_num);
            holder.total = (TextView) convertView.findViewById(R.id.cashier_static_total);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        CashierCashDto dto = dtos.get(position);
        holder.name.setText((position + 1)+". " + dto.getCashierName() + dto.getCashierNumber());
        holder.num.setText(String.valueOf(dto.getNum()));
        holder.total.setText(String.valueOf(DoubleSave.doubleSaveTwo(dto.getSale())));
        return convertView;
    }

    class ViewHolder {
        TextView name;
        TextView num;
        TextView total;
    }
}
